package com.yq.cp.utils;

import org.springframework.beans.BeanUtils;

import java.util.ArrayList;
import java.util.List;

public class BeanCopyUtil {

    public static <T>T copyObject(Object obj,Class<T> clazz){
        T t = null;
        try {
            t = clazz.newInstance();
            BeanUtils.copyProperties(obj,t);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
        return t;
    }


    public static <T>List<T> copyList(List source,Class<T> clazz){
        ArrayList<T> ts = new ArrayList<>();
        try {
            for (Object o : source) {
                T t = clazz.newInstance();
                BeanUtils.copyProperties(o,t);
                ts.add(t);
            }
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
        return ts;
    }



}
